/*
 * comandos.c
 *
 *  Created on: 11/12/2009
 *      Author: teledhil
 */

#include <stdio.h>
#include <string.h>
#include "comandos.h"
#include "variables.h"

int r_find(char *keyword) {

	fprintf(
			stdout,
			"1) Eric Clapton-If I could Change The %s.mp3\n   3.6M\n   69.244.21.191:6351\n",
			keyword);
	fprintf(stdout,
			"2) Gary Jules- Mad %s.mp3\n   7.23M\n   70.178.17.75:6346\n",
			keyword);

	return 0;
}

int r_get(int id) {

	return 0;
}

int r_info(int options) {

	switch (options) {

	case INFO_UPLOADS:
		fprintf(
				stdout,
				"Uploads:\n  1) Eric Clapton-If I could Change The World.mp3\n     62.195.18.49:6346\n     4.5M/5.16M\n");
		break;
	case INFO_DOWNLOADS:
		fprintf(
				stdout,
				"Downloads:\n  2) Gary Jules - Mad World.mp3\n     86.10.142.237\n     3.25K/2.86M\n");
		fprintf(
				stdout,
				"  3) Graham Colton Band - All the World Tonight.mp3\n     24.195.172.141\n     0/5.45M\n");
		break;
	case INFO_HOSTS:
		fprintf(
				stdout,
				"68.52.28.249:36661\n24.195.172.141:6348\n86.10.142.237:6346\n62.195.18.49:6348\n");
		break;
	default:

		break;
	}

	return 0;
}

int r_stop(int id) {

	return 0;
}

int r_exit() {

	return 0;
}

int r_set() {

	return 0;
}

int r_set_rowebcache(char *url) {

	if (strlen(url)>TAM_MAX_URL) {
		fprintf(stderr,"Longitud maxima del parametro rowebcache superada\n");
		return -1;
	}

	if (sprintf(URLrowebcache,"%s",url)<0) {
		return -1;
	}

	return 0;
}

int r_show_rowebcache() {

	fprintf(stdout,"rowebcache: \t%s\n", URLrowebcache);

	return 0;
}

int r_set_localport(int port) {

	if(port <1 || port> 65536){
		fprintf(stderr,"Puerto fuera de rango\n");
		return -1;
	}

	puertoLocal=port;

	return 0;
}

int r_show_localport() {

	fprintf(stdout,"localport: \t%d\n", puertoLocal);

	return 0;
}

int r_set_sharepath(char *path) {

	if (strlen(path)>TAM_MAX_NOMBRE_ARCHIVO) {
		fprintf(stderr,"Longitud maxima del parametro sharepath superada\n");
		return -1;
	}

	if (sprintf(sharePath,"%s",path)<0) {
		return -1;
	}

	return 0;
}

int r_show_sharepath() {

	fprintf(stdout,"sharepath: \t%s\n", sharePath);

	return 0;
}

int r_set_incomingpath(char *path) {

	if (strlen(path)>TAM_MAX_NOMBRE_ARCHIVO) {
		fprintf(stderr,"Longitud maxima del parametro incomingpath superada\n");
		return -1;
	}

	if (sprintf(incomingPath,"%s",path)<0) {
		return -1;
	}

	return 0;
}

int r_show_incomingpath() {

	fprintf(stdout,"incomingpath: \t%s\n", incomingPath);

	return 0;
}

int r_set_downloadpath(char *path) {

	if (strlen(path)>TAM_MAX_NOMBRE_ARCHIVO) {
		fprintf(stderr,"Longitud maxima del parametro downloadpath superada\n");
		return -1;
	}

	if (sprintf(downloadPath,"%s",path)<0) {
		return -1;
	}

	return 0;
}

int r_show_downloadpath() {

	fprintf(stdout,"downloadpath: \t%s\n", downloadPath);

	return 0;
}
